<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>教师账号注册审核</title>
    <link rel="stylesheet" href="../static/css/analysis.css">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css"/>


</head>
<body>
<header>
    <h1>教师账号注册审核</h1>
</header>

<div class="sidebar">
    <ul>
        <li class="logo">
            <a href="#">
                <span class="icon"><ion-icon name="person-outline"></ion-icon></span>
                <span class="text">个人头像</span>
            </a>
        </li>
        <li>
            <a href="./admin.html">
                <span class="icon"><ion-icon name="home-outline"></ion-icon></span>
                <span class="text">首页</span>
            </a>
        </li>
        <li>
            <a href="./check.html">
                <span class="icon"><ion-icon name="person-outline"></ion-icon></span>
                <span class="text">注册审核</span>
            </a>
        </li>
        <li>
            <a href="./management.html">
                <span class="icon"><ion-icon name="hammer-outline"></ion-icon></span>
                <span class="text">信息管理</span>
            </a>
        </li>
        <li>
            <a href="./analysis.html">
                <span class="icon"><ion-icon name="bar-chart-outline"></ion-icon></span>
                <span class="text">成绩管理</span>
            </a>
        </li>
        <li>
            <a href="./change_password.html">
                <span class="icon"><ion-icon name="settings-outline"></ion-icon></span>
                <span class="text">修改密码</span>
            </a>
        </li>
        <div class="bottom">
            <li>
                <a class="logout" style="cursor: pointer;">
                    <span class="icon"><ion-icon name="log-out-outline"></ion-icon></span>
                    <span class="text">登出</span>
                </a>
            </li>
        </div>
    </ul>
</div>

<div class="container">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>教师工号</th>
            <th>姓名</th>
            <!--<th>考勤成绩</th>-->
            <!--<th>课后作业</th>-->
            <!--<th>课堂测验</th>-->
            <!--<th>课堂互动</th>-->
            <!--<th>期中</th>-->
            <!--<th>期末</th>-->
            <!--<th>总分</th>-->
            <th>操作</th>
        </tr>
        </thead>
        <tbody></tbody>
    </table>

</div>
<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<script src="../src/js/userAction.js"></script>
<!--<script src = "../src/js/analysis.js"></script>-->
<script>
    function displayStudentList(data) {
        $('table tbody').empty();
        data.forEach(function (data) {

            $('table tbody').append(`
             <tr>
                  <td>${data.teacher_id}</td>
                  <td>${data.teacher_name}</td>
                  <td>
                       <button type="button" class="btn btn-sm btn-primary">同意</button>
                       <button type="button" class="btn btn-sm btn-danger">拒绝</button>
                  </td>
             </tr>
        `);
        });

    }

    function get_check_List() {
        $.ajax({
            url: "../api.php/get_verify",
            type: "GET",
            dataType: "json",
            // data:{'student_id': 10},
            success: function (res) {
                console.log('register', res);
                if (res["code"] === 200) {
                    // localStorage.setItem("verify", JSON.stringify(res["data"]));
                    displayStudentList(res["data"]);
                    let btn_agree = $(".btn-primary");
                    let btn_disagree = $(".btn-danger");
                    for (let i = 0; i < res["data"].length; ++i) {
                        btn_agree.eq(i).click(function () {
                            console.log(res["data"][i].teacher_id);
                            operate_verify(1, res["data"][i].teacher_id);

                        });

                        btn_disagree.eq(i).click(function () {
                            console.log(res["data"][i].teacher_id);
                            operate_verify(0, res["data"][i].teacher_id);
                        });
                    }
                }
            },
            error: function () {
                alert('出错了');
            }
        });
    }

    function operate_verify(action, user_id) {
        $.ajax('../api.php/operate_verify', {
            type: 'post',
            dataType: 'json',
            data: {'action': action, 'user_id': user_id},
            success: function (res) {
                if (res["code"] == 200) {
                    alert("成功审核！");
                    get_check_List();
                }
            }
        })
    }

    $(document).ready(function () {
        get_check_List();
    });
    $(".logout").click(function () {
        logout();
    })
</script>
</body>
</html>
